//
//  ChangeViewController.m
//  chanyouji
//
//  Created by xiacheng on 16/8/17.
//  Copyright © 2016年 chanyouji. All rights reserved.
//

#import "ChangeViewController.h"
#import "MainTabBarController.h"
@implementation ChangeViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self playMP];
}
- (void)playMP {
    //添加开机动画
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"preview" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:filePath];
    self.theMovie = [[MPMoviePlayerController alloc]initWithContentURL:url];
    [self.theMovie.view setFrame:[UIScreen mainScreen].bounds];
    
    [self.view addSubview:_theMovie.view];
    //视频设置
    self.theMovie.fullscreen = YES;
    self.theMovie.controlStyle = MPMovieControlStyleNone;
    //当视频播放完毕移除，防止黑屏
    if ([_theMovie respondsToSelector:@selector(prepareToPlay)]) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(stopPlayerCallback:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:self.theMovie];
        
        [self.theMovie prepareToPlay];
    }
   
}
-(void)stopPlayerCallback:(NSNotification*)aNotification {
    MPMoviePlayerController* theMovie = [aNotification object];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
                                                  object:theMovie];
    
    [theMovie.view removeFromSuperview];
    MainTabBarController *maintab = [[MainTabBarController alloc]init];
    [UIView transitionWithView:self.view.window duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        self.view.window.rootViewController = maintab;
    } completion:nil];

    
    
}


@end
